document.ready(function () {
    //初始化swiper插件
    let mySwiper = new Swiper('.mySwiper', {
        autoplay: true,
        pagination: {
            el: '.swiper-pagination',//分页按钮
            clickable: true,//分页按钮可点击
            autoplay: true,
        },
        navigation: {//前进后退按钮
            nextEl: '.swiper-button-next',
            prevEl: '.swiper-button-prev',
            autoplay: true,  //前进后退按钮循环

        },
        loop: true,  //前进后退按钮循环

    })



    /*需求:鼠标移入apiLink盒子,改变背景颜色(蓝色),改变图片的src路径 :xxx-c.svg,文字变为白色
    */

    let apiLink = document.querySelectorAll('.apiLink');
    let imgName = '';
    let imgFormat = '';
    apiLink.forEach(function (v) {
        v.addEventListener('mouseenter', function () {
            this.style.backgroundColor = '#1271ef';//改变背景颜色
            this.querySelector('p').style.color = '#fff';//改变文字颜色
            let imgPath = this.querySelector('img').src;//获取图片路径
            let imgNameIndex = imgPath.lastIndexOf('/');//获取图片名开头位置/的索引
            let imgFormatIndex = imgPath.lastIndexOf('.');//获取图片格式开头位置.的索引
            imgName = imgPath.substring(imgNameIndex + 1, imgFormatIndex);//获取图片名
            imgFormat = imgPath.substring(imgFormatIndex + 1);//获取格式名
            this.querySelector('img').src = `../imgs/${imgName}-c.${imgFormat}`//鼠标移入改变图片的路径
        })
        v.addEventListener('mouseleave', function () {
            this.style.backgroundColor = '#fff';
            this.querySelector('p').style.color = '#000';
            this.querySelector('img').src = `../imgs/${imgName}.${imgFormat}`
        })
    })

    
    /*需求:blankList跑马灯效果*/

    let blankList = document.querySelectorAll('.blankList');
    let supportEnterprise2 = document.querySelector('.supportEnterprise2');
    let index = 0;
    let ratation = function () {
        blankList[index].classList.remove('active');
        ++index;
        if (index == blankList.length) index = 0;
        blankList[index].classList.add('active');
    }
    let timer = setInterval(ratation, 1000);
    supportEnterprise2.addEventListener('mouseover', function () {
        clearInterval(timer);
    })
    supportEnterprise2.addEventListener('mouseout', function () {
        timer = setInterval(ratation, 1000);
    })



    /*需求:滚轮到底部显示回到顶部按钮,点击按钮回到顶部*/
    let backTop = document.querySelector('.backTop');
    window.addEventListener('scroll', function () {
        //滚动条滚动的距离
        let sTop = document.documentElement.scrollTop;
        //整个滚动区域的高度
        let sHeight = document.documentElement.scrollHeight;
        //窗口高度,可见高度
        let curHeight = document.documentElement.clientHeight;
        if (sHeight - sTop == curHeight) {
            backTop.style.opacity = '1';
        } else {
            backTop.style.opacity = '0';
        }
    })
    //点击回到顶部按钮,回到顶部
    backTop.addEventListener('click', function () {
        buffer(document.documentElement, { scrollTop: 0 });
    })
    //改变回到顶部按钮背景图片
    backTop.addEventListener('mouseover', function () {
        backTop.style.backgroundPosition = "-163px -97px";
    })
    backTop.addEventListener('mouseout', function () {
        backTop.style.backgroundPosition = "-163px -56px";
    })

})